#include "../src/mylog.hpp"
#include "../extend/extend_RollByTimeSink.hpp" // 日志落地方式扩展

//普通测试
void test()
{
    mylog::getLogger("async_logger")->debug("debug message,%s", mylog::getLogger("async_logger")->name().c_str());
    mylog::getLogger("async_logger")->info("info message,%s", mylog::getLogger("async_logger")->name().c_str());
    mylog::getLogger("async_logger")->warn("warn message,%s", mylog::getLogger("async_logger")->name().c_str());
    mylog::getLogger("async_logger")->error("error message,%s", mylog::getLogger("async_logger")->name().c_str());
    mylog::getLogger("async_logger")->fatal("fatal message,%s", mylog::getLogger("async_logger")->name().c_str());
}

//功能测试
void test2()
{
    for(int i = 0; i < 1000000; ++i)
    {
        mylog::getLogger("async_logger")->error("error message,%s", mylog::getLogger("async_logger")->name().c_str());
    }
}

int main()
{
    std::unique_ptr<mylog::LoggerBuilder> builder(new mylog::GlobalLoggerBuilder());
    builder->buildLoggerType(mylog::LoggerType::LOGGER_ASYNC);
    //builder->buildEnableUnSafeAsync();
    builder->buildLoggerName("async_logger");
    builder->buildLoggerLevel(mylog::LogLevel::value::WARN);
    builder->buildLoggerFormatter();
    builder->buildLoggerSink<mylog::StdoutSink>();
    builder->buildLoggerSink<mylog::FileSink, std::string>("./test_file/testLog.log");
    builder->buildLoggerSink<mylog::RollBySizeSink, std::string, size_t>("./test_rollFile/testLog", 1024 * 1024);
    builder->buildLoggerSink<extend::RollByTimeSink, std::string, extend::TimeGap>("./test_rollTime/testLog", extend::TimeGap::Second);
    builder->build();

    mylog::DEBUG("debug message,%s", mylog::rootLogger()->name().c_str());
    mylog::INFO("info message,%s", mylog::rootLogger()->name().c_str());
    mylog::WARN("warn message,%s", mylog::rootLogger()->name().c_str());
    mylog::ERROR("error message,%s", mylog::rootLogger()->name().c_str());
    mylog::FATAL("fatal message,%s", mylog::rootLogger()->name().c_str());

    //test();
    //test2();

    return 0;
}